// @charset "utf-8";
/**
 * 赚钱效应画图
 */
define(function(require, exports, module) {

	var zqxyChart = {
		isShowShdata: true,
		changeSize: function () {
			var windowWidth = $(window).width(),
				windowHeight = $(window).height();
			$('.container').height(windowHeight).width(windowWidth);
			$('.tab-content-item').height(windowHeight - 26);
			$('.chart-content, .chart-c').height(windowHeight - 26 - 15)
				.width(windowWidth - 4);

			// $('#view_div_dqfxchart').height(windowHeight - 26 - 5);

			$('.reading-content').height(windowHeight - 30)
				.width(windowWidth - 4);

			var readChartWidth = (windowWidth - 22) * 0.4;
			$('#view_div_readchart').height(readChartWidth * 0.7)
				.width(readChartWidth);

			// xgsg
			$('.xgsg-content').height(windowHeight - 26).width(windowWidth - 10);
			$('.data-box').height(windowHeight - 26 - 28 - 17);
		},
		render: function(zqxyData, shData, param, xAxisDate) {
			var self = this;
			var chartConfig = {
				xAxis: commonMethod.xAxis,
				tickInterval: 120,
				tickPositions: [0, 120, 241],
				toolTipDate: '',
				zqxyData: commonMethod.emptyData,
				shData: commonMethod.emptyData,
				newZqxyData: '--',
				newShData: '--'
			};
			if (zqxyData.length && shData.length) {
				if (zqxyData[zqxyData.length - 1] == null) {
					chartConfig.newZqxyData = '--';
				} else {
					chartConfig.newZqxyData = zqxyData[zqxyData.length - 1];
				}
				chartConfig.newShData = shData[shData.length - 1];

				if (param.period === 'min') {
					chartConfig.zqxyData = commonMethod.completeData(zqxyData);
					chartConfig.shData = commonMethod.completeData(shData);
					chartConfig.toolTipDate = commonMethod.dateSplit(param.begin).substr(5) + ' ';

				} else {
					chartConfig.zqxyData = zqxyData;
					chartConfig.shData = shData;
					chartConfig.xAxis = xAxisDate;
					chartConfig.tickInterval = Math.ceil(xAxisDate.length / 10);
					chartConfig.tickPositions = null;
					toolTipDate = '';
				}
				// alert(JSON.stringify(chartConfig));
			}
			self.renderChart(chartConfig);
		},
		renderChart: function(chartConfig) {
			var self = this;
			var $chartDom = $('#view_div_zqxychart');
			var xAxis = chartConfig.xAxis,
				tickInterval = chartConfig.tickInterval,
				tickPositions = chartConfig.tickPositions,
				toolTipDate = chartConfig.toolTipDate,
				zqxyData = chartConfig.zqxyData,
				shData = chartConfig.shData,

				newZqxyData = chartConfig.newZqxyData,
				newShData = chartConfig.newShData;

			var yellowColor = '#efefef';
			if (commonMethod.thsSkin == 'white') {
				yellowColor = '#e08900';
			}
			var chartOption = {
				credits: {
					enabled: false
				},
				title: {
					text: ''
				},
				chart: {
					backgroundColor: 'rgba(0,0,0,0)',
					style: {
						fontFamily: 'arial, Microsoft yahei'
					},
					marginTop: 36,
					marginLeft: 40,
					events : {
						click : function () {
							$('.interval-btn').addClass('hide');
						}
					}
				},
				series: [{
					name: '昨日涨停表现',
					type: 'line',
					color: '#ff3232',
					lineWidth: 1,
					marker: {
						enabled: false,
						states: {
							hover: {
								fillColor: '#ff3232',
								radius: 2,
								lineColor: 'rgba(255, 255, 255, 1)',
								lineWidthPlus: 1
							}
						}
					},
					data: zqxyData,
					point: {
						events: {
							mouseOver: function() {
								$('.zqxy-legend:first').text(this.y);
							}
						}
					}
				}, {
					name: '上证',
					type: 'line',
					color: yellowColor,
					lineWidth: 1,
					marker: {
						enabled: false,
						states: {
							hover: {
								fillColor: '#efefef',
								radius: 2,
								lineColor: 'rgba(200, 200, 200, 1)',
								lineWidthPlus: 1
							}
						}
					},
					data: shData,
					point: {
						events: {
							mouseOver: function() {
								$('.zqxy-legend:eq(1)').text(this.y);
							}
						}
					},
					yAxis: 1,
					visible: self.isShowShdata
				}],
				plotOptions: {
					series: {
						stickyTracking: false,
						events: {
							legendItemClick: function() {
								if (this.name == '昨日涨停表现') {
									commonMethod.thsQuote.switchCode('883900');
									return false;
								} else {
									var visibility = this.visible ? 'visible' : 'hidden';
									if (visibility === 'visible') {
										self.isShowShdata = false;
									} else {
										self.isShowShdata = true;
									}
									// var ser = self.zqxyHighcahrts.series[1];
									// this.series.hide();
								}
							}
						}
					},
					line: {
						states: {
							hover: {
								lineWidthPlus: 0
							}
						}
					}
				},
				xAxis: {
					lineWidth: 1,
					tickLength: 4,
					lineColor: '#808080',
					tickColor: '#808080',
					tickInterval: tickInterval,
					tickPositions: tickPositions,
					title: {
						text: ''
					},
					categories: xAxis,
					gridLineWidth: 0,
					labels: {
						align: 'center',
						rotation: 0,
						style: {
							color: '#afafaf'
						}
					},
					showLastLabel: true
				},
				yAxis: [{
					allowDecimals : false,
					lineWidth: 1,
					tickColor: '#808080',
					tickPosition: 'outside',
					gridLineWidth: 0,
					tickLength: 4,
					tickWidth: 1,
					title: {
						text: ''
					},
					lineColor: '#808080',
					labels: {
						format: '{value}%',
						style: {
							color: '#afafaf'
						},
						x: -7
					}
				}, {
					allowDecimals: false,
					lineWidth: 1,
					tickColor: '#808080',
					tickPosition: 'outside',
					gridLineWidth: 0,
					tickLength: 4,
					tickWidth: 1,
					title: {
						text: ''
					},
					lineColor: '#808080',
					labels: {
						style: {
							color: '#afafaf'
						},
						x: 7,
						format: '{value}'
					},
					opposite: true
				}],
				legend: {
					enabled: true,
					align: 'right',
					floating: false,
					verticalAlign: 'top',
					symbolHeight: 20,
					symbolWidth: 14,
					itemStyle: {
						color: '#dedede',
						fontFamily: 'simsun',
						fontWeight: 'normal'
					},
					itemHiddenStyle: {},
					itemHoverStyle: {
						color: '#bbb'
					},
					useHTML: true,
					labelFormatter: function() {
						if (this.name === '昨日涨停表现') {
							return '<span class="zqxy-legend-item textline">' + this.name + '<i class="zqxy-legend view_i_zqxydata">' + newZqxyData + '</i>%</span>';
						}
						if (this.name === '上证') {
							return '<span class="zqxy-legend-item">' + this.name + '<i class="zqxy-legend view_i_zqxyshdata">' + newShData + '</i></span>';
						}
					},
					y: -8
				},
				tooltip: {
					shared: true,
					enabled: true,
					style: {
						color: '#acb8aa',
						padding: 2
					},
					hideDelay: 10,
					backgroundColor: '#410080',
					borderWidth: 0,
					crosshairs: [{
						width: 1,
						color: '#afafaf'
					}],
					formatter: function() {
						return toolTipDate + this.x;
					},
					positioner: function(labelWidth, labelHeight, point) {
						var x = point.plotX + 42 - parseInt(labelWidth / 1);
						return {
							x: x,
							y: $('#view_div_zqxychart').height() - 36
						};
					}
				}
			};
			self.changeSize();
			$chartDom.highcharts(chartOption);
			this.zqxyHighcahrts = $chartDom.highcharts();
		},
		zqxyHighcahrts: null,
		reflowChart: function() {
			if (this.zqxyHighcahrts != null) {
				this.zqxyHighcahrts.reflow();
			}
		}
	};

	module.exports = zqxyChart;
});